<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            class StackObjct {
                constructor() {
                    this._items = {};
                    this._count = 0;
                }
                //进栈
                push(val) {
                    this._items[this._count++] = val;
                }
                //出栈
                pop() {
                    let item = this._items[--this._count];
                    delete this._items[this._count];
                    return item;
                }
                //判断是否为空
                isEmpty() {
                    return !Object.keys(this._items).length && !this._count;
                }
                //获取栈的长度
                getLength() {
                    return this._count;
                }
                //获取栈顶的元素
                getItem() {
                    return this._items[this._count - 1];
                }
                get items() {
                    throw new Error("禁止直接访问栈内的元素");
                }
                get count() {
                    throw new Error("禁止直接访问栈内的元素c");
                }
            }
        </script>
    </body>
</html>
